<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增【请填写功能名称】')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-log-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">员工：</label>
                    <div class="col-sm-8">
                        <select name="staffId" class="form-control" id="staffSelect">
                            <option value="">请选择员工</option>
                        </select>
                    </div>
                </div>
            </div>
<!--            <div class="col-xs-12">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-3 control-label">员工名称：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="staffName" class="form-control" type="text">-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <input type="hidden" name="staffName" id="staffName">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">模具：</label>
                    <div class="col-sm-8">
                        <select name="modlId" class="form-control" id="modlSelect">
                            <option value="">请选择模具</option>
                        </select>
                    </div>
                </div>
            </div>
            <!--<div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">模具名称：</label>
                    <div class="col-sm-8">
                        <input name="modlName" class="form-control" type="text">
                    </div>
                </div>
            </div>-->
            <input type="hidden" name="modlName" id="modlName">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">加工单价(整数单位为分)：</label>
                    <div class="col-sm-8">
                        <input name="modlProcesCost" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">处理数量：</label>
                    <div class="col-sm-8">
                        <input name="procesNum" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">总加工单价：</label>
                    <div class="col-sm-8">
                        <input name="totalProcesCost" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <input name="remark" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/staffModlLog"

        $(function() {
            // 页面加载时获取员工列表和模具列表
            loadStaffList();
            loadModlList();

            // 监听员工选择变化
            $('#staffSelect').change(function() {
                var $selected = $(this).find('option:selected');
                var staffName = $selected.data('name') || '';
                $('#staffName').val(staffName);
            });

            // 监听模具选择变化
            $('#modlSelect').change(function() {
                var $selected = $(this).find('option:selected');
                var modlName = $selected.data('name') || '';
                $('#modlName').val(modlName);
            });
        });

        // 加载员工列表
        function loadStaffList() {
            $.ajax({
                url: '/system/staff/list', // 替换为实际的员工列表接口
                type: 'POST',
                success: function(response) {
                    var $select = $('#staffSelect');
                    $.each(response.rows || [], function(index, item) {
                        $select.append(
                            $('<option>')
                                .val(item.id)
                                .text(item.staffName)
                                .data('name', item.staffName)
                        );
                    });
                }
            });
        }

        // 加载模具列表
        function loadModlList() {
            $.ajax({
                url: '/system/modl/list', // 替换为实际的模具列表接口
                type: 'POST',
                success: function(response) {
                    var $select = $('#modlSelect');
                    $.each(response.rows || [], function(index, item) {
                        $select.append(
                            $('<option>')
                                .val(item.id)
                                .text(item.modlName)
                                .data('name', item.modlName)
                        );
                    });
                }
            });
        }

        $("#form-log-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-log-add').serialize());
            }
        }
    </script>
</body>
</html>